package com.example.wendao.view.viewholder;


import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.wendao.R;
import com.example.wendao.common.PageUtils;
import com.example.wendao.common.ViewHolderBind;
import com.example.wendao.model.entity.Forum;
import com.example.wendao.model.entity.Goods;


/**
 * A simple {@link Fragment} subclass.
 */
public class MallViewHolder extends RecyclerView.ViewHolder implements ViewHolderBind<Goods> {
    private TextView goodsname,goodinfo;
    private RelativeLayout layout;


    public MallViewHolder(@NonNull ViewGroup viewGroup) {
        super(PageUtils.inflateItemView(viewGroup, R.layout.fragment_mall_list));
        goodsname=itemView.findViewById(R.id.goodsname);
        goodinfo=itemView.findViewById(R.id.goodinfo);
        layout=itemView.findViewById(R.id.mall_jumppage);
    }


    @Override
    public void bindTo(Goods good) {
        String name,info;
        if(good.getGoodName().length()>10){
            name = good.getGoodName().substring(0, 10) + "...";
        }
        else{
            name=good.getGoodName();
        }
        goodsname.setText(name);
        if(good.getGoodInfo().length()>20){
            info= good.getGoodInfo().substring(0,20)+"...";
        }else{
            info=good.getGoodInfo();
        }
        goodinfo.setText(info);
        layout.setOnClickListener(v -> {
            // 传值
            Bundle bundle = new Bundle();
            bundle.putInt("goodid", good.getGoodId());
            // 需添加配置
            Navigation.findNavController(v).navigate(R.id.action_fragment_mall_to_fragment_mall_details, bundle);
        });
    }

}
